import entity.Area;

import java.util.List;

/**
 * 使用工具类(优化),完成表联结查询,要求查询某个地区->城市->省份.(或者反过来),
 * sql文件见Script.sql.将Java核心代码和自定义工具类上传即可。
 * ```sql
 * SELECT
 * t_area.AreaName,
 * t_city.CityName,
 * t_province.ProvinceName
 * FROM
 * t_area INNER join
 * t_city on t_area.ParentId = t_city.CityId
 * INNER JOIN
 * t_province on t_city.ParentId = t_province.ProvinceId
 * where t_area.AreaName='湖里区'
 * @author: knowno
 * @create: 2025-09-19 09:18
 * @Version 1.0
 **/
public class Test_Query_Multi_Table {
    public static void main(String[] args) {

        String sql ="SELECT\n" +
                "t_area.AreaName areaName,\n" +
                "t_city.CityName cityName,\n" +
                "t_province.ProvinceName provinceName\n" +
                "FROM\n" +
                "t_area INNER join \n" +
                "t_city on t_area.ParentId = t_city.CityId\n" +
                "INNER JOIN\n" +
                "t_province on t_city.ParentId = t_province.ProvinceId\n" +
                "where t_area.AreaName='湖里区'";
        List<Area> list = DBUtil.exQuery(sql, Area.class);

        for (Area area : list) {
            System.out.println(area.getAreaName()+"\t"+area.getCity().getCityName()+"\t"+area.getCity().getProvince().getProvinceName());
        }

    }
}
